# -*- coding: utf-8 -*-
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from web.article import ViewArticle, TemplatePage, CreateUpdateArticle
from web.comment import AddComment, DeleteComment
from web.rss import RssFeed
from web.stats import SubmitVersion, ShowStats, SetVersion, RobotsTXT
from web.constants import get_admin_user
from google.appengine.api import users
import os
from google.appengine.ext.webapp import template
from recaptcha.client import captcha

class LoginPage(webapp.RequestHandler):
    def get(self):
        user = get_admin_user()  
        if user:        
            self.response.out.write('Hello, ' + user.nickname())
        else:
            self.redirect(users.create_login_url(self.request.uri))
class HomePage(webapp.RequestHandler):
    def get(self):  
        self.redirect("/")         

application = webapp.WSGIApplication([                                     
                                      ('/login', LoginPage),
                                      ('/edit', CreateUpdateArticle),
                                      ('/rss', RssFeed),
                                      ('/version', SubmitVersion),
                                      ('/set_version', SetVersion),
                                      ('/add_commnet', AddComment),
                                      ('/delete_comment', DeleteComment),
                                      ('/stats', ShowStats),                                      
                                      (r'/article/(.*)/(.*)', ViewArticle),
                                      (r'/article/(.*)', ViewArticle),
                                      (r'/(.*)/(.*)/(.*)', TemplatePage),
                                      (r'/(.*)/(.*)', TemplatePage),
                                      ('/page_404', HomePage),
                                      ('/robots.txt', RobotsTXT),
                                      (r'/(.*)', TemplatePage),
                                      
                                      
                                      ], debug=True)


def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
